<template>
  <div class="my-app">
    <c-tabs :labels="['我的应用']">
      <!-- <template #right>
        <div class="page-turn" v-if="total > carouselStep">
          <div class="left" @click="$refs['myAppCarousel'].prev()"></div>
          <div class="right" @click="$refs['myAppCarousel'].next()"></div>
        </div>
      </template> -->
    </c-tabs>
    <div class="app-list">
      <a-carousel ref="myAppCarousel" :dots="false" :infinite="false" arrows>
        <div slot="prevArrow" class="custom-slick-arrow" style="left: 0;zIndex: 1">
          <img src="@/assets/images/arrow-1.png" alt="" />
        </div>
        <div slot="nextArrow" class="custom-slick-arrow" style="right: 24px;zIndex: 1">
          <img src="@/assets/images/arrow-2.png" alt="" />
        </div>

        <div v-for="(item, idx) in myApp" :key="idx" class="carousel-block">
          <a class="item item-a" href="javascript:;" v-for="(value, key) in item" :key="key" @click="goSso(value.id)">
            <div class="item-icon">
              <img :src="value.images ? value.images : require('@/assets/images/bg-6.png')" alt="" />
              <span class="undo-num" v-if="value.pendCount">{{ value.pendCount }}</span>
            </div>
            <div class="label">{{ value.systemNameCn }}</div>
          </a>
          <template v-if="item.length < carouselStep">
            <div class="item" v-for="value in carouselStep - item.length" :key="'key' + value"></div>
          </template>
        </div>
      </a-carousel>
    </div>
  </div>
</template>

<script lang="ts">
import Base from "@/controllers/base.ts";
import { Component } from "vue-property-decorator";
import { Carousel } from "ant-design-vue";
import CTabs from "./cTabs.vue";

@Component({
  name: "MyApp",
  components: {
    CTabs,
    ACarousel: Carousel
  }
})
export default class MyApp extends Base {
  private carouselStep = 6;
  private total = 0;
  private dataSource: any[] = [];

  private created() {
    this.ssoConfigAllList();
  }

  private get myApp() {
    const step = this.carouselStep;
    const _return: any[] = Array.from({ length: Math.ceil(this.dataSource.length / step) }, () => []);
    for (let i = 0; i < _return.length; i++) {
      for (let j = i * step; j < i * step + step; j++) {
        if (this.dataSource[j]) {
          _return[i].push(this.dataSource[j]);
        } else {
          break;
        }
      }
    }
    return _return;
  }

  private async goSso(id: string) {
    const res = await this.$api.GetSsoUrl(id);
    if (res && res.code === 200) {
      if (res.data.URL) {
        this._goto(res.data.URL, res.data.openWay);
      } else {
        this.$message.error("跳转地址为空");
      }
    }
  }

  private async ssoConfigAllList() {
    const res = await this.$api.SsoConfigAllList();
    if (res && res.code === 200) {
      this.total = res.total;
      this.dataSource = res.rows;
    }
  }
}
</script>

<style lang="less" scoped>
@import "~@/assets/style/mixin.less";
.my-app {
  .scale(width, 500px);
  background: #ffffff;
  box-shadow: 0px 0px 10px 0px rgba(83, 112, 239, 0.22);
  display: flex;
  flex-direction: column;

  .app-list {
    flex: 1;
    overflow: hidden;
    .scale(padding-top, 8px);
  }

  .item-icon {
    .scale(width, 80px);
    .scale(margin-bottom, 6px);
    .scale(height, 80px);
    .scale(border-radius, 80px);
    background: rgba(188, 202, 212, 0.1);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;

    img {
      .scale(width, 49px);
    }
  }
  .undo-num {
    position: absolute;
    background: #dd1b29;
    border-radius: 12px;
    height: 20px;
    width: 30px;
    color: white;
    line-height: 20px;
    display: block;
    font-size: 12px;
    text-align: center;
    top: 8px;
    right: -15px;
  }

  .carousel-block {
    width: 100%;
    flex-shrink: 0;
    display: flex !important;
    flex-wrap: wrap;
    transition-duration: 0.5s;
    justify-content: space-around;
    .scale(padding-top, 10px);
    .scale(padding-bottom, 10px);
    .scale(padding-left, 30px);
    .scale(padding-right, 30px);

    .item {
      .scale(padding-top, 10px);
      .scale(padding-bottom, 10px);
      text-align: center;
      flex-shrink: 0;
      .scale(width, 115px);
      // .scale(height, 135px);
    }

    .item-a:hover {
      border-radius: 2px;
      box-shadow: 0px 0px 10px 0px rgba(83, 112, 239, 0.22);
    }

    .label {
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      margin-top: 6px;
    }
  }
  .page-turn {
    display: flex;
    & > div {
      .scale(width, 29px);
      .scale(height, 29px);
      cursor: pointer;
    }

    .left {
      background: url("~@/assets/images/bg-11.png") right center no-repeat;
      background-size: contain;
    }

    .right {
      background: url("~@/assets/images/bg-12.png") left center no-repeat;
      background-size: contain;
    }
  }
}
</style>
